package codec

// Prophetic defines the codec use for apollo-prophetic code generate

import "strconv"

// PropheticError ...
type PropheticError struct {
	Name       string                   `json:"name"`
	Message    string                   `json:"message"`
	Extensions PropheticErrorExtensions `json:"extensions"`
}

// PropheticErrorExtensions ...
type PropheticErrorExtensions struct {
	Code string `json:"code"`
}

// ErrorList exports error
var ErrorList []*PropheticError

func init() {
	for name, code := range Variables {
		// Register Name into Error
		nameBase[code.codec] = name
		ErrorList = append(ErrorList, &PropheticError{
			Name:    name,
			Message: code.Message(),
			Extensions: PropheticErrorExtensions{
				Code: strconv.Itoa(code.Code()),
			},
		})
	}
}
